/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao;

import e.odbo.DB;
import e.odbo.data.dao.ModifiedLogDAO;
import com.openbravo.bean.ServiceCalendarWeakLine;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;

import com.openbravo.data.loader.sentence.StaticSentence;
import com.openbravo.data.loader.table.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class ServiceCalendarWeakLineDAO extends ModifiedLogDAO<ServiceCalendarWeakLine>{

    public ServiceCalendarWeakLineDAO(I_Session s) {
        super(s);
    }


    @Override
    public TableDefinition getTable() {
        return new TableDefinition(
                "SERVICECALENDARWEAKLINE",
                new Field[]{
                          new Field("ID",Datas.STRING,Formats.STRING),
                          new Field("SERVICECALENDAR_ID",Datas.STRING,Formats.STRING),
                          new Field("DAYINWEAK",Datas.INT,Formats.INT),
                          new Field("STARTDATE",Datas.TIMESTAMP, Formats.TIMESTAMP),
                          new Field("ENDDATE",Datas.TIMESTAMP, Formats.TIMESTAMP),
                          new Field("LASTMODIFIED",Datas.TIMESTAMP, Formats.TIMESTAMP)
                },
                new int[]{0});
    }

    @Override
    public void writeInsertValues(DataWrite dp, ServiceCalendarWeakLine obj) throws BasicException {
         dp.setString(1,obj.getId());
         dp.setString(2, obj.getServiceCalenderId());
         dp.setInt(3,obj.getDayInWeak());
         dp.setTimestamp(4,obj.getStart());
         dp.setTimestamp(5,obj.getEnd());
         dp.setTimestamp(6,obj.getLastModified());
    }

    @Override
    public void writeUpdateValues(DataWrite dp, ServiceCalendarWeakLine obj) throws BasicException {
         dp.setString(1,obj.getId());
         dp.setString(2, obj.getServiceCalenderId());
         dp.setInt(3,obj.getDayInWeak());
         dp.setTimestamp(4,obj.getStart());
         dp.setTimestamp(5,obj.getEnd());
         dp.setTimestamp(6,obj.getLastModified());

         dp.setString(7,obj.getKey());
    }

    @Override
    public Class getSuportClass() {
        return ServiceCalendarWeakLine.class;
    }

    public ServiceCalendarWeakLine readValues(DataRead dr,ServiceCalendarWeakLine obj) throws BasicException {
        if(obj==null)
        	obj=new ServiceCalendarWeakLine();
        obj.setId(dr.getString(1));
        obj.setServiceCalenderId(dr.getString(2));
        obj.setDayInWeak(dr.getInt(3));
        obj.setStart(dr.getTimestamp(4));
        obj.setEnd(dr.getTimestamp(5));
        obj.setLastModified(dr.getTimestamp(6));
        return obj;
    }

    public List<ServiceCalendarWeakLine> listServiceCalendarWeakLineByService(String serviceId) throws BasicException {
        return new StaticSentence(s,DB.getListSQL(this,"W")+",SERVICECALENDAR S,SERVICE C WHERE W.SERVICECALENDAR_ID=S.ID AND S.ID=C.SERVICECALENDAR_ID AND C.ID="+serviceId,null,this).list();
    }

}
